#include<iostream>
#include<memory>
using namespace std;

class Computer
{
public:
   void SetBoard(const string& board)
   {
       _board = board;
   }    

   void SetDisplay(const string& display)
   {
      _display = display;
   }

   virtual void setOs() = 0; //不同电脑的操作系统不同
   void ShowParams()
   {
     cout << "computer params: " << endl;
     cout << "Board: " << _board << endl;
     cout << "Display: " << _display << endl;
     cout << "OS:" << _os << endl;
   }

protected:
   string _board; //主板
   string _display; //显示屏
   string _os; //操作系统
};

class Mac : public Computer
{
public:
    void setOs()
    {
        _os = "MAC OS X12";
    }   

};

class Builder
{
public:
  virtual void BuildBoard(const string& board) = 0;
  virtual void BuildDisplay(const string& display) = 0;    
  virtual void BuildOS() = 0;
  virtual std::shared_ptr<Computer> build() = 0;
};

class MacBuilder : public Builder
{
public:
  MacBuilder():
  _computer(new Mac())
  {}

  void BuildBoard(const string& board) override
  {
     _computer->SetBoard(board);
  }
  void BuildDisplay(const string& display) override
  {
      _computer->SetDisplay(display);
  }    
  void BuildOS() override
  {
     _computer->setOs();
  }
  std::shared_ptr<Computer> build() override
  {
     return _computer;
  }
private:
   std::shared_ptr<Computer> _computer;  
};

class Director
{
public: 
   Director(Builder* builder)
   :_builder(builder)
   {}

   void Construct(const string& board,const string& display)
   {
      _builder->BuildDisplay(display);
      _builder->BuildBoard(board);
      _builder->BuildOS();
   }

private:
   shared_ptr<Builder> _builder;   
};

int main()
{
    Builder* builder = new MacBuilder();
    unique_ptr<Director> director(new Director(builder));
    director->Construct("华硕主板","三星显示器");
    shared_ptr<Computer> mac = builder->build();
    mac->ShowParams();
    return 0;
}